<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{{.title}}</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.2/font/bootstrap-icons.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
    <link href="/static/css/toast.css" rel="stylesheet">
    <link href="/static/css/main.css" rel="stylesheet">
</head>
<body>
    <div class="container-fluid">
        <div class="row">
            <!-- 侧边栏 -->
            <nav class="col-md-3 col-lg-2 d-md-block sidebar collapse">
                <div class="position-sticky pt-3">
                    <h5 class="sidebar-heading px-3 mt-4 mb-1 tech-line">
                        <i class="bi bi-cpu"></i> 数据迁移工具
                    </h5>
                    <ul class="nav flex-column">
                        <li class="nav-item">
                            <a class="nav-link" href="/migration">
                                <i class="bi bi-diagram-3"></i> 迁移任务配置
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link active" href="/execution">
                                <i class="bi bi-list-task"></i> 任务列表
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="/datasource">
                                <i class="bi bi-hdd-network"></i> 数据源管理
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="/template">
                                <i class="bi bi-filter-circle"></i> 过滤模板
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="/masking">
                                <i class="bi bi-shield-check"></i> 脱敏规则
                            </a>
                        </li>
                    </ul>
                </div>
            </nav>

            <!-- 主内容区 -->
            <main class="col-md-9 ms-sm-auto col-lg-10 px-md-4 content-area">
                <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
                    <h1 class="h2">迁移任务列表</h1>
                    <div class="d-flex gap-2">
                        <button class="btn btn-outline-primary" onclick="refreshMigrationTasks()">
                            <i class="bi bi-arrow-clockwise"></i> 刷新
                        </button>
                        <button class="btn btn-outline-secondary" onclick="exportTasks()">
                            <i class="bi bi-cloud-download"></i> 导出记录
                        </button>
                    </div>
                </div>

                <!-- 批量操作栏 -->
                <div id="batchActions" class="d-flex justify-content-between align-items-center p-3 mb-3" 
                     style="background: var(--card-bg); border: 1px solid var(--border-color); border-radius: 8px; display: none;">
                    <div class="d-flex align-items-center">
                        <span class="text-muted me-3">已选择 <span id="selectedCount" class="fw-bold text-primary">0</span> 个任务</span>
                        <button class="btn btn-sm btn-outline-secondary me-2" onclick="clearAllSelection()">
                            <i class="bi bi-x"></i> 清除选择
                        </button>
                    </div>
                    <div class="d-flex gap-2">
                        <button class="btn btn-sm btn-outline-success" onclick="batchStartTasks()">
                            <i class="bi bi-play me-1"></i>批量启动
                        </button>
                        <button class="btn btn-sm btn-outline-warning" onclick="batchStopTasks()">
                            <i class="bi bi-stop me-1"></i>批量停止
                        </button>
                        <button class="btn btn-sm btn-outline-info" onclick="batchExportTasks()">
                            <i class="bi bi-download me-1"></i>批量导出
                        </button>
                        <button class="btn btn-sm btn-outline-danger" onclick="batchDeleteTasks()">
                            <i class="bi bi-trash me-1"></i>批量删除
                        </button>
                    </div>
                </div>

<!-- 搜索和筛选 -->
<div class="search-filters mb-4">
    <div class="row">
        <div class="col-md-6">
            <div class="input-group">
                <span class="input-group-text bg-transparent border-end-0">
                    <input type="checkbox" class="form-check-input me-2" id="selectAllTasks" onchange="toggleSelectAll()" title="全选/取消全选">
                    <i class="bi bi-search text-muted"></i>
                </span>
                <input type="text" class="form-control border-start-0" id="taskSearch" 
                       placeholder="搜索任务名称..." onkeyup="filterTasks()">
            </div>
        </div>
        <div class="col-md-2">
            <select class="form-select" id="taskStatusFilter" onchange="filterTasks()">
                <option value="">所有状态</option>
                <option value="initializing">初始化中</option>
                <option value="running">运行中</option>
                <option value="paused">已暂停</option>
                <option value="completed">已完成</option>
                <option value="failed">失败</option>
                <option value="stopped">已停止</option>
            </select>
        </div>
        <div class="col-md-2">
            <select class="form-select" id="taskDateFilter" onchange="filterTasks()">
                <option value="">所有时间</option>
                <option value="today">今天</option>
                <option value="week">本周</option>
                <option value="month">本月</option>
            </select>
        </div>
        <div class="col-md-2">
            <select class="form-select" id="taskSortFilter" onchange="sortTasks()">
                <option value="newest">最新创建</option>
                <option value="oldest">最早创建</option>
                <option value="name">按名称</option>
                <option value="progress">按进度</option>
            </select>
        </div>
    </div>
</div>

<!-- 任务统计 -->
<div class="row mb-4">
    <div class="col-md-2">
        <div class="stat-card">
            <div class="stat-number" id="totalTasks">0</div>
            <div class="stat-label">总任务数</div>
        </div>
    </div>
    <div class="col-md-2">
        <div class="stat-card">
            <div class="stat-number text-primary" id="runningTasks">0</div>
            <div class="stat-label">运行中</div>
        </div>
    </div>
    <div class="col-md-2">
        <div class="stat-card">
            <div class="stat-number text-success" id="completedTasks">0</div>
            <div class="stat-label">已完成</div>
        </div>
    </div>
    <div class="col-md-2">
        <div class="stat-card">
            <div class="stat-number text-danger" id="failedTasks">0</div>
            <div class="stat-label">失败</div>
        </div>
    </div>
    <div class="col-md-2">
        <div class="stat-card">
            <div class="stat-number text-warning" id="pausedTasks">0</div>
            <div class="stat-label">暂停</div>
        </div>
    </div>
    <div class="col-md-2">
        <div class="stat-card">
            <div class="stat-number text-secondary" id="stoppedTasks">0</div>
            <div class="stat-label">已停止</div>
        </div>
    </div>
</div>

<!-- 任务卡片列表 -->
<div class="row" id="migrationTasksContainer">
    <!-- 任务卡片将在这里动态生成 -->
</div>

<!-- 空状态 -->
<div id="emptyState" class="text-center py-5" style="display: none;">
    <i class="bi bi-inbox display-1 text-muted"></i>
    <h4 class="text-muted mt-3">暂无迁移任务</h4>
    <p class="text-muted">还没有创建任何迁移任务，<a href="/migration">点击这里</a>创建第一个任务</p>
</div>
            </main>
        </div>
    </div>

    <!-- 弹框容器 -->
    <div class="toast-container" id="toastContainer"></div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
    <script src="/static/js/common.js"></script>
    <script src="/static/js/execution.js"></script>
</body>
</html>